package com.multithreading.chart1.join;

/**
 * @author chenqb
 * @project_name: java-multithreading
 * @package_name: com.cqb.join
 * @ClassName: joinDeom2
 * @description: TODO
 * Author by cqb, Date on 2020/6/27，23:30
 * PS: Not easy to write code, please indicate.
 */
public class JoinDeom2 {

    public static void main(String[] args) throws InterruptedException {
        //创建线程one
        Thread threadOne= new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("threadOne begin run!");
                for (; ; ) {
                }
            }
        });
        //获取主线程
        final Thread mainThread = Thread.currentThread();
        //创建线程Two
        Thread threadTwo=new Thread(new Runnable() {
//            int count=0;
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
//                    for (int i=0;i<100;i++){
//                        System.out.println("threadTwo is running "+i);
//                    }
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                //中断主线程
                mainThread.interrupt();
//                System.out.println(count);
            }

        });
        //启动子线程
        threadOne.start();
        //延迟一秒启动线程
        threadTwo.start();
        try {//等待线程one执行结束
            threadOne.join();
        }catch (InterruptedException e){
            System.out.println("main thread:"+e);
        }
    }
}
